<template>
	<view class="container">
		<u-toast ref="uToast"></u-toast>
		<view class="form">
			<view class="item">
				<u--input v-model="form.real_name" placeholder="请输入创作者昵称" border="surround"></u--input>
			</view>
			<view class="item">
				<u--input v-model="form.mobile" placeholder="请输入联系方式,如:微信18786709420" border="surround"></u--input>
			</view>
			<view class="item">
				<u--textarea v-model="form.remarks" placeholder="请输入个人主页简介" border="surround" :count="true">
				</u--textarea>
			</view>
			<view class="item">
				<u--textarea v-model="form.statement" placeholder="请输入创作声明" border="surround" :count="true">
				</u--textarea>
			</view>
			<view class="item">
				<view class="label">店铺状态</view>
				<view class="value">
					<u-radio-group placement="row" v-model="form.is_close">
						<view class="radio">
							<u-radio label="开启" name="10">
							</u-radio>
						</view>
						<view class="radio">
							<u-radio label="关闭" name="20">
							</u-radio>
						</view>
					</u-radio-group>
				</view>
			</view>
			<view class="item" @click="onSubmit">
				<view class="submit">
					<u-button shape="circle" color="linear-gradient(to right,#fa3534,#fa3534)" text="更新资料"></u-button>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		detail,
		modify
	} from '@/api/user.js';
	export default {
		data() {
			return {
				cover: [],
				userInfo: {},
				form: {
					mobile:'',
					statement:'',
					real_name: '',
					remarks: '',
					is_close: '10'
				}
			};
		},
		onShow() {
			this.getUser()
		},
		methods: {
			onSubmit() {
				let _this = this;
				modify(this.form)
					.then(res => {
						if (res.code == 1) {
							_this.$refs.uToast.show({
								type: 'success',
								message: '更新成功~！',
								complete() {
									_this.getUser()
								}
							});
						}
					})
					.catch(err => {});
			},
			getUser() {
				detail({}).then(res => {
					this.userInfo = res.data.userInfo
					if (this.userInfo) {
						this.form.real_name = this.userInfo.real_name
						this.form.is_close = this.userInfo.is_close + ''
						this.form.mobile = this.userInfo.mobile
						this.form.statement = this.userInfo.statement
						if(this.userInfo.remarks){
							this.form.remarks = this.userInfo.remarks
						}
					}
				}).catch(err => {

				})
			}
		}
	}
</script>

<style lang="scss">
	.form {
		width: 86%;
		margin: 15rpx auto;
		min-height: 320rpx;
		background-color: #fff;
		border-radius: 10rpx;
		padding: 15rpx 30rpx;

		.item {
			margin: 30rpx 0rpx;
			display: flex;
			flex-direction: row;
			align-items: center;

			.submit {
				width: 94%;
				margin: 0 auto;
			}

			.value {
				.radio {
					margin-right: 15rpx;
				}
			}

			.label {
				min-width: 100rpx;
				margin-right: 15rpx;
			}
		}
	}
</style>
